/**
 * 
 */
package com.ginger.rabbitmq.exchange.api.ack;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

/**
 * @Description: Ginger消费者
 * @author 姜锋
 * @date 2019年3月30日 下午12:14:46
 * @version V1.0
 */
public class GingerConsumer extends DefaultConsumer {
	/** 日志对象 **/
	private final static Logger logger = LoggerFactory.getLogger(GingerConsumer.class);
	private Channel channel;

	/**
	 * @param channel
	 */
	public GingerConsumer(Channel channel) {
		super(channel);
		this.channel = channel;
	}
	/*
	 * （非 Javadoc）
	 * @see com.rabbitmq.client.DefaultConsumer#handleDelivery(java.lang.String,
	 * com.rabbitmq.client.Envelope, com.rabbitmq.client.AMQP.BasicProperties, byte[])
	 */
	@Override
	public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body)
			throws IOException {
		logger.info("----- consumer message -----");
		logger.info("properties:" + properties);
		logger.info("body:" + new String(body));
		// channel.basicNack(推送标记, 是否批量, 是否重回队列)
		// channel.basicNack(envelope.getDeliveryTag(), false, true);
		channel.basicAck(envelope.getDeliveryTag(), false);
	}
}
